<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Default_Model_Trackdonhang extends ZF_DB{
    protected $_table_name = "trackdonhang" ;
    
    protected $_matrackdh;
    protected $_dsmadhtuban;
    protected $_dsmadhcapcon;
    protected $_loinhuan;
    protected $_bonus;
    
    public function getMaTrackDH(){
        return $this->_matrackdh;
    }
    public function setMaTrackDH($matrackdh){
        $this->_matrackdh = $matrackdh;
    }
    public function getDsMaDHTuBan(){
        return $this->_dsmadhtuban;
    }
    public function setDsMaDHTuBan($dsmadhtuban){
        $this->_dsmadhtuban = $dsmadhtuban;
    }
    public function getMaDHCapCon(){
        return $this->_dsmadhcapcon;
    }
    public function setMaDHCapCon($dsmadhcapcon){
       $this->_dsmadhcapcon = $dsmadhcapcon;
    }
    public function getLoiNhuan(){
        return $this->_loinhuan;
    }
    public function setLoiNhuan($loinhuan){
        $this->_loinhuan = $loinhuan;
    }
    
    public function getBonus(){
        return $this->_bonus;
    }
    public function setBonus($bonus){
        $this->_bonus = $bonus;
    }
    
    public function insert($matrackdh, $dsmadhtuban, $dsmadhcapcon, $loinhuan, $bonus){
        
        if($matrackdh){             
                $data =  array(
                    'MaTrackDH' =>$matrackdh,
                    'DSMaDHTuBan'=>$dsmadhtuban,
                    'DSMaDHCapCon'=>$dsmadhcapcon,
                    'LoiNhuan'=>$loinhuan,
                    'Bonus'=>$bonus);
            return $this->db->insert($this->_table_name,$data);
	}
        return -1;
	
    }
   
    public function update($matrackdh, $res){
        $where  = "MaTrackDH='" . $matrackdh . "'";
        $data =  array(
                    'DSMaDHTuBan' =>$res['DSMaDHTuBan'],
                    'DSMaDHCapCon'=>$res['DSMaDHCapCon'],
                    'LoiNhuan'=>$res['LoiNhuan'],
                    'Bonus'=>$res['Bonus']);
	return $this->db->update(
                $this->_table_name,
                $data,$where);
    }
    
    public function getById($matrackdh){
        if($matrackdh)
	{
		$select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.MaTrackDH = ?", $matrackdh);
		
		$data = $this->db->fetchRow($select);
                if($data){
			$this->_matrackdh = $data['MaTrackDH'];
			$this->_dsmadhtuban = $data['DSMaDHTuBan'];
			$this->_dsmadhcapcon = $data['DSMaDHCapCon'];
                        $this->_loinhuan = $data['LoiNhuan'];
                        $this->_bonus = $data['Bonus'];
		}                
		return $data;
	}
	return -1;
    }
   
    public function listAll(){
        $select = $this->db->select()
                ->from($this->_table_name);
        $data = $this->db->fetchAll($select);
	return $data;
    }
    public function delete(){
            $this->getById($this->_id);
            $this->_active = 0;
            return $this->update();
    }
}
?>
